﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;

namespace DataAccess
{
    public abstract class AbstractDataAccess : IDataAccess
    {
        #region IDataAccess 成员

		#region Support Property & Method

		public abstract DatabaseType DatabaseType{get;}

		public abstract IDbConnection DbConnection{get;}

		public abstract IDbTransaction BeginTransaction();

		public void Open()
		{
			if(this.DbConnection.State.Equals(ConnectionState.Closed))
			{
				this.DbConnection.Open();
			}
		}

		public void Close()
		{
			this.DbConnection.Close();
		}

		public bool IsClosed
		{
			get
			{
				return this.DbConnection.State.Equals( ConnectionState.Closed);
			}
		}

		#endregion

		#region ExecuteNonQuery
		public int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			return this.ExecuteNonQuery(commandType, commandText, null,null,null);
		}

		public int ExecuteNonQuery(string commandText)
		{
			return this.ExecuteNonQuery(CommandType.Text, commandText, null,null,null);
		}
		public int ExecuteNonQuery(string commandText, QueryParameterCollection commandParameters)
		{
			return this.ExecuteNonQuery(CommandType.Text, commandText, commandParameters,null,null);
		}
		public int ExecuteNonQuery(DataRow row,SqlStruct sqlStruct)
		{
			QueryParameterCollection commandParameters = new QueryParameterCollection();
			return this.ExecuteNonQuery(CommandType.Text, null,commandParameters ,row,sqlStruct);
		}
		public int ExecuteNonQuery(CommandType commandType, string commandText, QueryParameterCollection commandParameters)
		{
			return this.ExecuteNonQuery(commandType, commandText, commandParameters,null,null);
		}
		public abstract int ExecuteNonQuery(CommandType commandType, string commandText, QueryParameterCollection commandParameters,DataRow row,SqlStruct sqlStruct);

		
		#endregion ExecuteNonQuery

		#region ExecuteDataSet
		public DataSet ExecuteDataset(CommandType commandType, string commandText)
		{
			return ExecuteDataset(commandType, commandText, null ,new DataSet(),null);
		}

		public DataSet ExecuteDataset(string commandText)
		{
			return ExecuteDataset(CommandType.Text, commandText, null ,new DataSet(),null);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters)
		{
			return ExecuteDataset(commandType, commandText, commandParameters,new DataSet(),null);
		}

		public DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters)
		{
			return ExecuteDataset(CommandType.Text, commandText, commandParameters ,new DataSet(),null);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText,DataSet ds)
		{
			return ExecuteDataset(commandType, commandText, null ,ds,null);
		}

		public DataSet ExecuteDataset(string commandText,DataSet ds)
		{
			return ExecuteDataset(CommandType.Text, commandText, null ,ds,null);
		}
		public DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,DataSet ds)
		{
			return ExecuteDataset(CommandType.Text, commandText, commandParameters , ds,null);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText,string tableName)
		{
			return ExecuteDataset(commandType, commandText, null ,new DataSet(),tableName);
		}

		public DataSet ExecuteDataset(string commandText,string tableName)
		{
			return ExecuteDataset(CommandType.Text, commandText, null ,new DataSet(),tableName);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,string tableName)
		{
			return ExecuteDataset(commandType, commandText, commandParameters,new DataSet(),tableName);
		}

		public DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,string tableName)
		{
			return ExecuteDataset(CommandType.Text, commandText, commandParameters ,new DataSet(),tableName);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText,DataSet ds,string tableName)
		{
			return ExecuteDataset(commandType, commandText, null ,ds,tableName);
		}

		public DataSet ExecuteDataset(string commandText,DataSet ds,string tableName)
		{
			return ExecuteDataset(CommandType.Text, commandText, null ,ds,tableName);
		}
		public DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,DataSet ds,string tableName)
		{
			return ExecuteDataset(CommandType.Text, commandText, commandParameters , ds,tableName);
		}

		public DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,DataSet ds)
		{
			return ExecuteDataset(commandType, commandText, commandParameters , ds,null);
		}
		
		public abstract DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,DataSet ds,string tableName);		

		public abstract DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,DataSet ds,int startRecord,int maxRecords,string tableName);
		
		#endregion ExecuteDataSet;

		#region ExecuteReader	
		public IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			return ExecuteReader(commandType,commandText,null);
		}

		public IDataReader ExecuteReader(string commandText)
		{
			return ExecuteReader(CommandType.Text,commandText,null);
		}
		public IDataReader ExecuteReader(string commandText, QueryParameterCollection commandParameters)
		{
			return ExecuteReader(CommandType.Text,commandText,commandParameters);
		}

		public abstract IDataReader ExecuteReader(CommandType commandType, string commandText, QueryParameterCollection commandParameters);
		
		#endregion ExecuteReader	

		#region ExecuteScalar	
		public object ExecuteScalar(CommandType commandType, string commandText)
		{
			return ExecuteScalar(commandType, commandText, null);
		}

		public object ExecuteScalar(string commandText)
		{
			return ExecuteScalar(CommandType.Text, commandText, null);
		}
		public object ExecuteScalar(string commandText, QueryParameterCollection commandParameters)
		{
			return ExecuteScalar(CommandType.Text, commandText, commandParameters);
		}

		public abstract object ExecuteScalar(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

		#endregion ExecuteScalar	

		#region ExecuteXmlReader	
		public XmlReader ExecuteXmlReader(CommandType commandType, string commandText)
		{
			return ExecuteXmlReader(commandType,commandText,null);
		}

		public XmlReader ExecuteXmlReader(string commandText)
		{
			return ExecuteXmlReader(CommandType.Text,commandText,null);
		}

		public XmlReader ExecuteXmlReader(string commandText, QueryParameterCollection commandParameters)
		{
			return ExecuteXmlReader(CommandType.Text,commandText,commandParameters);
		}

		public abstract XmlReader ExecuteXmlReader(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

		#endregion ExecuteXmlReader

		#endregion
	
    }
}
